<template>
  <h1>一个人的信息</h1>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>工作种类：{{ job.type }}</h2>
  <h2>工作薪水{{ job.salary }}</h2>
  <button @click="changeInfo">修改个人信息</button>
</template>

<script>
import {ref} from 'vue'
export default {
  name: "App",
  setup() {
    // 响应式数据要通过ref()包裹
    let name = ref('张三');
    let age = ref(18);
    let job = ref({ 
      //如果对对象、数组类型的数据使用ref包裹，实际上在内部会转换成reactive包裹
      type:"前端工程师",
      salary:"30K"
    })

    function changeInfo() {
      // 修改相应数据
      name.value = "李四";
      age.value = 38;
      job.value.type = 'UI设计师'
      job.value.salary = '10K'
      console.log(name,age); //RefImpl对象 => reference implement（引用实现）
      console.log(job.value); //Prexy对象
    }

    return {
      name,
      age,
      job,
      changeInfo,
    };
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
</style>
